home *** CD-ROM | disk | FTP | other *** search
Wrap
(*************************************************** Ant Movie Catalog importation script www.antp.be/software/moviecatalog/ [Infos] Authors=(c) 2002 Piotr Kardasz Title=Filmweb (PL) Description=Movie importation script for Filmweb info & small picture Site=http://www.filmweb.pl Language=PL Version=1.1 Requires=3.5.0.1 Comments=05.10.2003 Improvements made by Adma's|07.10.2003 Modifications by Adma's to import small picture|03.03.2004 Modyfications by BestiaPL support for new movie database links|20.12.2004 Modyfications by Atomek2000 support for new site design Filmweb|14.02.2005 Improvements made by Adma's|02.05.2005 Small modyfication by Mi$ta$|08.05.2005 Modyfications by Atomek2000 for correct rating, requirement AMC 3.5.0.1 for correct download pictures (bug in AMC 3.5.0.0) License=This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. | GetInfo=1 [Options] ***************************************************) program FilmWeb; var MovieName: string; Link: string; function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer; var i: Integer; begin result := -1; if StartAt < 0 then StartAt := 0; for i := StartAt to List.Count-1 do if Pos(Pattern, List.GetString(i)) <> 0 then begin result := i; Break; end; end; procedure DelSpace(var Value: String); var FullValue: String; Counter: Integer; begin if Value <> '' then begin FullValue := FullValue + StrGet(Value, 1); for Counter := 2 to Length(Value) do begin if StrGet(Value, Counter) <> ' ' then FullValue := FullValue + StrGet(Value, Counter) else if StrGet(FullValue, Length(FullValue)) <> ' ' then FullValue := FullValue + ' '; end; Value := FullValue; end end; procedure DecodeHTML(var Value: String); var FullValue, CharCode: String; Counter: Integer; begin if Value <> '' then begin FullValue := ''; Counter := 1; repeat if StrGet(Value, Counter) <> '&' then begin CharCode := copy(Value, Counter, 1); case CharCode of '▒': CharCode := '╣'; '╢': CharCode := '£'; 'í': CharCode := 'Ñ'; '╝': CharCode := 'ƒ'; 'ª': CharCode := 'î'; '¼': CharCode := 'Å'; end; FullValue := FullValue + CharCode; Counter := Counter + 1; end else begin CharCode := copy(Value, Counter, 7); case CharCode of 'ą': FullValue := FullValue + '╣'; 'ć': FullValue := FullValue + 'µ'; 'ę': FullValue := FullValue + 'Ω'; 'ł': FullValue := FullValue + '│'; 'ń': FullValue := FullValue + '±'; 'ó': FullValue := FullValue + '≤'; 'ś': FullValue := FullValue + '£'; 'ź': FullValue := FullValue + 'ƒ'; 'ż': FullValue := FullValue + '┐'; 'Ą': FullValue := FullValue + 'Ñ'; 'Ć': FullValue := FullValue + '╞'; 'Ę': FullValue := FullValue + '╩'; 'Ł': FullValue := FullValue + 'ú'; 'Ń': FullValue := FullValue + '╤'; 'Ó': FullValue := FullValue + '╙'; 'Ś': FullValue := FullValue + 'î'; 'Ź': FullValue := FullValue + 'Å'; 'Ż': FullValue := FullValue + '»'; 'Š': FullValue := FullValue + ' '; 'š': FullValue := FullValue + 'í'; 'Ţ': FullValue := FullValue + 'í'; 'ţ': FullValue := FullValue + 'ú'; 'Ť': FullValue := FullValue + 'ñ'; 'ť': FullValue := FullValue + 'Ñ'; 'Ŧ': FullValue := FullValue + 'î'; 'ŧ': FullValue := FullValue + 'º'; 'Ũ': FullValue := FullValue + '¿'; 'ũ': FullValue := FullValue + '⌐'; 'Ű': FullValue := FullValue + '¬'; 'ű': FullValue := FullValue + '½'; 'Ų': FullValue := FullValue + '¼'; 'ų': FullValue := FullValue + '¡'; 'Ŵ': FullValue := FullValue + '«'; 'ŵ': FullValue := FullValue + '»'; 'Ŷ': FullValue := FullValue + '░'; 'ŷ': FullValue := FullValue + '▒'; 'Ÿ': FullValue := FullValue + '▓'; 'ƀ': FullValue := FullValue + '┤'; 'Ɓ': FullValue := FullValue + '╡'; 'Ƃ': FullValue := FullValue + '╢'; 'ƃ': FullValue := FullValue + '╖'; 'Ƅ': FullValue := FullValue + '╕'; 'ƅ': FullValue := FullValue + '╣'; 'Ɔ': FullValue := FullValue + '║'; 'Ƈ': FullValue := FullValue + '╗'; 'ƈ': FullValue := FullValue + '╝'; 'Ɖ': FullValue := FullValue + '╜'; 'Ɛ': FullValue := FullValue + '╛'; 'Ƒ': FullValue := FullValue + '┐'; 'ƒ': FullValue := FullValue + '└'; 'Ɠ': FullValue := FullValue + '┴'; 'Ɣ': FullValue := FullValue + '┬'; 'ƕ': FullValue := FullValue + '├'; 'Ɩ': FullValue := FullValue + '─'; 'Ɨ': FullValue := FullValue + '┼'; 'Ƙ': FullValue := FullValue + '╞'; 'ƙ': FullValue := FullValue + '╟'; 'Ȁ': FullValue := FullValue + '╚'; 'ȁ': FullValue := FullValue + '╔'; 'Ȃ': FullValue := FullValue + '╩'; 'ȃ': FullValue := FullValue + '╦'; 'Ȅ': FullValue := FullValue + '╠'; 'ȅ': FullValue := FullValue + '═'; 'Ȇ': FullValue := FullValue + '╬'; 'ȇ': FullValue := FullValue + '╧'; 'Ȉ': FullValue := FullValue + '╨'; 'ȉ': FullValue := FullValue + '╤'; 'Ȑ': FullValue := FullValue + '╥'; 'ȑ': FullValue := FullValue + '╙'; 'Ȓ': FullValue := FullValue + '╘'; 'ȓ': FullValue := FullValue + '╒'; 'Ȕ': FullValue := FullValue + '╓'; 'ȕ': FullValue := FullValue + '╫'; 'Ȗ': FullValue := FullValue + '╪'; 'ȗ': FullValue := FullValue + '┘'; 'Ș': FullValue := FullValue + '┌'; 'ș': FullValue := FullValue + '█'; 'Ƞ': FullValue := FullValue + '▄'; 'ȡ': FullValue := FullValue + '▌'; 'Ȣ': FullValue := FullValue + '▐'; 'ȣ': FullValue := FullValue + '▀'; 'Ȥ': FullValue := FullValue + 'α'; 'ȥ': FullValue := FullValue + 'ß'; 'Ȧ': FullValue := FullValue + 'Γ'; 'ȧ': FullValue := FullValue + 'π'; 'Ȩ': FullValue := FullValue + 'Σ'; 'ȩ': FullValue := FullValue + 'σ'; 'Ȱ': FullValue := FullValue + 'µ'; 'ȱ': FullValue := FullValue + 'τ'; 'Ȳ': FullValue := FullValue + 'Φ'; 'ȳ': FullValue := FullValue + 'Θ'; 'ȴ': FullValue := FullValue + 'Ω'; 'ȵ': FullValue := FullValue + 'δ'; 'ȶ': FullValue := FullValue + '∞'; 'ȷ': FullValue := FullValue + 'φ'; 'ȸ': FullValue := FullValue + 'ε'; 'ȹ': FullValue := FullValue + '∩'; 'ɀ': FullValue := FullValue + '≡'; 'Ɂ': FullValue := FullValue + '±'; 'ɂ': FullValue := FullValue + '≥'; 'Ƀ': FullValue := FullValue + '≤'; 'Ʉ': FullValue := FullValue + '⌠'; 'Ʌ': FullValue := FullValue + '⌡'; 'Ɇ': FullValue := FullValue + '÷'; 'ɇ': FullValue := FullValue + '≈'; 'Ɉ': FullValue := FullValue + '°'; 'ɉ': FullValue := FullValue + '∙'; 'ɐ': FullValue := FullValue + '·'; 'ɑ': FullValue := FullValue + '√'; 'ɒ': FullValue := FullValue + 'ⁿ'; 'ɓ': FullValue := FullValue + '²'; 'ɔ': FullValue := FullValue + '■'; 'ɕ': FullValue := FullValue + ' '; '%DF;': FullValue := FullValue + '▀'; '4': FullValue := FullValue + '"'; else FullValue := FullValue + CharCode; end; Counter := Counter + 7; end; until Counter > Length(Value); HTMLDecode(FullValue); Value := FullValue; end end; procedure AddMoviesTitles(Page: TStringList; var LineNr: Integer); var Line: string; MovieTitle, MovieAddress: string; StartPos, EndPos: Integer; begin LineNr := FindLine('<b>filmy</b>:', Page, LineNr); if LineNr > -1 then begin PickTreeAdd('Znaleziono filmy:', ''); Line := Page.GetString(LineNr); repeat if (Pos('<a title=', Line) > 0) and (Pos('zobacz wiΩcej', Line) <= 0) then begin StartPos := pos('<a title=', Line) + 10; Line := copy(Line, StartPos, Length(Line) - StartPos); MovieTitle := copy(Line, 1, pos('href', Line) - 3); DecodeHTML(MovieTitle); HTMLRemoveTags(MovieTitle); StartPos := pos('href=', Line) + 6; Line := copy(Line, StartPos, Length(Line)); if pos('"', Line) > 0 then MovieAddress:= Copy(Line, 1, Pos('"', Line) - 1) else MovieAddress:= Copy(Line, 1, Pos('class=', Line) - 3); PickTreeAdd(MovieTitle, MovieAddress); end; LineNr := LineNr + 1; Line := Page.GetString(LineNr); until Pos('</table>', Line) > 0; end else break; end; procedure AnalyzePage(Address: string); var Page: TStringList; LineNr: Integer; begin Page := TStringList.Create; Page.Text := GetPage(Address); Link:=Address; if pos('<div class="tyt">', Page.Text) > 0 then AnalyzeMoviePage(Page) else if pos('href=', Page.Text) > 0 then begin PickTreeClear; LineNr := 0; AddMoviesTitles(Page, LineNr); if PickTreeExec(Address) then AnalyzePage(Address); end; Page.Free; end; procedure AnalyzeMoviePage(Page: TStringList); var Line, Value, FullValue: string; LineNr, Counter: Integer; StartPos, EndPos: Integer; PageOpis: TStringList; LineNrOpis: Integer; AddressOpis: String; begin // Tytu│ polski LineNr := FindLine('<div class="tyt">', Page, 0); if LineNr > -1 then begin Line := Page.GetString(LineNr); Line := Page.GetString(LineNr+1); StartPos := 8; Line := copy(Line, StartPos, Length(Line) - StartPos + 1); DecodeHTML(Line); SetField(fieldTranslatedTitle, Line); end // Tytu│ oryginalny Value:=Line; LineNr := FindLine('<span class="styt">', Page, 0); if LineNr > -1 then begin Line := Page.GetString(LineNr); if (pos('<span class="styt">(', Line) > 0) or (pos('<span class="styt"> </span>', Line) > 0) then Line:=Value else begin StartPos := pos('<span class="styt">', Line) + 19; Line := copy(Line, StartPos, Length(Line) - StartPos); StartPos := pos('</', Line) - 1; Line := copy(Line, 1, StartPos); if copy(Line, Length(Line), 1) = ' ' then Line := copy(Line, 1, Length(Line) - 1); end; DecodeHTML(Line); SetField(fieldOriginalTitle, Line); end // îrednia ocena LineNr := FindLine('</b>/10', Page, 0); if LineNr > -1 then begin Line := Page.GetString(LineNr); StartPos := pos('">', Line) + 2; Line := copy(Line, StartPos, Length(Line) - StartPos); StartPos := pos('</b>', Line); Line := copy(Line, 1, StartPos - 1); Line:=IntToStr(Round(StrToInt(copy(Line, 1, Length(Line)-3),0)*10+StrToInt(copy(Line, 3, 2), 0) / 10)); //zaokr╣glenie oceny do dziesiΩtnej Value:=copy(Line, 1, Length(Line)-1)+','+copy(Line, Length(Line), 1); SetField(fieldRating, Value); end // Kategoria LineNr := FindLine('genre.id', Page, 0); if LineNr > -1 then begin Line := Page.GetString(LineNr); Value := ''; while Pos('genre.id=', Line) > 0 do begin StartPos := pos('">', Line) + 2; Line := copy(Line, StartPos, Length(Line) - StartPos + 1); StartPos := pos('</', Line); Value:= Value + copy(Line,1, StartPos - 1) + ' / '; end; Value := copy(Value, 1, Length(Value) - 3); DecodeHTML(Value); SetField(fieldCategory, Value); end // Kraj LineNr := FindLine('country.id', Page, 0); if LineNr > -1 then begin Line := Page.GetString(LineNr); Value := ''; while Pos('country.id=', Line) > 0 do begin StartPos := pos('">', Line) + 2; Line := copy(Line, StartPos, Length(Line) - StartPos + 1); StartPos := pos('</', Line); Value:= Value + copy(Line,1, StartPos - 1) + ' , '; end; Value := copy(Value, 1, Length(Value) - 3); DecodeHTML(Value); SetField(fieldCountry, Value); end // Rok produkcji LineNr := FindLine('<span class="styt">(', Page, 0); if LineNr > -1 then begin Line := Page.GetString(LineNr); StartPos := pos(')</span>', Line); Value := copy(Line, StartPos-4, 4); SetField(fieldYear, Value); end // Re┐yseria LineNr := FindLine('re┐yseria', Page, 0); if LineNr > -1 then begin Line := Page.GetString(LineNr); StartPos:= Pos('re┐yseria', Line) + 9; Line:= Copy(Line, StartPos, Length(Line)); Value:=''; repeat StartPos:= Pos('">', Line) + 2; Line:= Copy(Line, StartPos, Length(Line) - StartPos); Value:= Value + Copy(Line, 1, Pos('</a>', Line) - 1) + ', '; until Pos('">', Line) <= 0; Value:= Copy(Value, 1, Length(Value) - 2); DecodeHTML(Value); SetField(fieldDirector, Value); end // Producent // LineNr := FindLine('>producent:</td>', Page, 0); // if LineNr > -1 then // begin // Line := Page.GetString(LineNr); // StartPos := pos('>producent:</td>', Line) + 16; // Line := copy(Line, StartPos, Length(Line) - StartPos); // Value := copy(Line, 1, pos('</a></td></tr>', Line) - 1); // HTMLRemoveTags(Value); // DecodeHTML(Value); // SetField(fieldProducer, Value); // end // Czas trwania LineNr := FindLine('czas trwania:', Page, 0); if LineNr > -1 then begin Line := Page.GetString(LineNr); StartPos := pos('czas trwania:', Line) + 14; Line := copy(Line, StartPos, Length(Line) - StartPos + 1); SetField(fieldLength, Line); end // Opis filmu LineNr := FindLine('alt="o filmie"', Page, 0); if LineNr > -1 then begin if FindLine('... <a class="n" href="', Page, LineNr) > 0 then begin LineNr := FindLine('... <a class="n" href="', Page, LineNr); Line := Page.GetString(LineNr); StartPos := pos('... <a class="n" href="', Line) + 23; Line := copy(Line, StartPos, Length(Line) - StartPos); StartPos := pos('">', Line); Line := copy(Line, 1, StartPos - 1); AddressOpis := Line; SetField(fieldComments, 'Dodatkowe opisy filmu na stronie: ' + AddressOpis); PageOpis := TStringList.Create; PageOpis.Text := GetPage(AddressOpis); LineNrOpis := FindLine('<li>', PageOpis, 0); if LineNrOpis > -1 then begin LineNrOpis:= LineNrOpis + 1; Line := PageOpis.GetString(LineNrOpis); While FindLine('<li>', PageOpis, LineNrOpis) >0 do begin LineNrOpis := FindLine('<li>', PageOpis, LineNrOpis); LineNrOpis:= LineNrOpis + 1; end; LineNrOpis:=LineNrOpis-1; Line:=''; EndPos:=FindLine('</li>', PageOpis, LineNrOpis); For StartPos:=LineNrOpis to EndPos do Line := Line + PageOpis.GetString(StartPos) + ' '; StartPos := pos('<li>', Line); Line := copy(Line, StartPos, Length(Line) - StartPos); HTMLRemoveTags(Line); while copy(Line,1,1) = ' ' do Line:=copy(Line,2,Length(Line) - 1); if copy(Line, Length(Line), 1) = ' ' then Line := copy(Line, 1, Length(Line) - 1); end; PageOpis.Free; end else begin Line := Page.GetString(LineNr+1); Line:=StringReplace(Line, #9, ' '); HTMLRemoveTags(Line); while copy(Line,1,1) = ' ' do Line:=copy(Line,2,Length(Line) - 1); end; DecodeHTML(Line); Line:=StringReplace(Line, chr(34),chr(39)); // zamiana cudzyslowu na apostrof DelSpace(Line); SetField(fieldDescription, Line); end // Obsada LineNr := FindLine('alt="obsada"', Page, 0); if LineNr > -1 then begin LineNr:= LineNr + 1; Line := Page.GetString(LineNr); While Pos('title="', Line) <= 0 do begin LineNr:= LineNr + 1; Line := Page.GetString(LineNr); end; Value := ''; repeat if Pos('title=', Line) > 0 then begin Line:= Copy(Line, Pos('title=', Line) + 7, Length(Line)); StartPos:= Pos('">', Line) + 2; Line:= Copy(Line, StartPos, Length(Line)); Value:= Value + Copy(Line, 1, Pos('</a', Line) - 1) + ', '; end; LineNr:= LineNr + 1; Line := Page.GetString(LineNr); until Pos('</table>', Line) > 0; //align="right"><a class="n" Value := copy(Value, 1, Length(Value) - 2); DecodeHTML(Value); SetField(fieldActors, Value); end //URL setField(fieldURL, Link); //Foto Value:= ''; LineNr:= FindLine('<img src="http://gfx.filmweb.pl', Page, 0); if LineNr > -1 then begin Line:= Page.GetString(LineNr); StartPos:= Pos('src=', Line) + 5; Line:= Copy(Line, StartPos, Length(Line)); Line:= Copy(Line, 1, Pos('alt=', Line) - 3); HTMLRemoveTags(Line); DecodeHTML(Line); DelSpace(Line); GetPicture(Line); end; end; begin if CheckVersion(3,5,0) then begin MovieName := GetField(fieldOriginalTitle); if MovieName = '' then MovieName := GetField(fieldTranslatedTitle); if Input('FilmWeb Import', 'Podaj tytu│ filmu:', MovieName) then begin MovieName:=StringReplace(MovieName, '╣', chr(177)); // Zamiana na ISO-8859-2 MovieName:=StringReplace(MovieName, 'µ', chr(230)); MovieName:=StringReplace(MovieName, 'Ω', chr(234)); MovieName:=StringReplace(MovieName, '│', chr(179)); MovieName:=StringReplace(MovieName, '±', chr(241)); MovieName:=StringReplace(MovieName, '≤', chr(243)); MovieName:=StringReplace(MovieName, '£', chr(182)); MovieName:=StringReplace(MovieName, 'ƒ', chr(188)); MovieName:=StringReplace(MovieName, '┐', chr(191)); MovieName:=StringReplace(MovieName, 'Ñ', chr(161)); MovieName:=StringReplace(MovieName, '╞', chr(198)); MovieName:=StringReplace(MovieName, '╩', chr(202)); MovieName:=StringReplace(MovieName, 'ú', chr(163)); MovieName:=StringReplace(MovieName, '╤', chr(209)); MovieName:=StringReplace(MovieName, '╙', chr(211)); MovieName:=StringReplace(MovieName, 'î', chr(166)); MovieName:=StringReplace(MovieName, 'Å', chr(172)); MovieName:=StringReplace(MovieName, '»', chr(175)); MovieName:=StringReplace(MovieName, ' ', '+'); AnalyzePage('http://filmweb.pl/Find?query=' + MovieName + '&category=1'); end; end else ShowMessage('Skrypt wymaga programu Ant Movie Catalog w wersji 3.5.0.1 lub nowszej'); end.